package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.product.mapper.BaseCategory2Mapper;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: atguigu
 * @create: 2023-07-22 15:23
 */
@Service
public class BaseCategory2ServiceImpl extends ServiceImpl<BaseCategory2Mapper, BaseCategory2> implements BaseCategory2Service {


    /**
     * 根据一级分类ID查询该分类下二级分类列表
     *
     * @param category1Id
     * @return
     */
    @Override
    public List<BaseCategory2> getCategory2List(Long category1Id) {
        //1.创建条件对象 TODO QueryWrapper问题编写条件每次都需要从数据库中复制字段名称 不方便
        //QueryWrapper<BaseCategory2> queryWrapper = new QueryWrapper<>();
        //queryWrapper.eq("category1_id", category1Id);


        //1. 支持Lambda表达式Wrapper
        LambdaQueryWrapper<BaseCategory2> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BaseCategory2::getCategory1Id, category1Id);
        //设置查询字段
        queryWrapper.select(BaseCategory2::getId, BaseCategory2::getName);
        //2.执行列表查询
        return this.list(queryWrapper);
    }
}
